var tpl = _include('./index.html');
appendCss(_include('./index.less?_ac=less'));
var scenes = require('/src/vue/scenes/index.js');
var uploadimg = require('/src/vue/uploadimg/index.js');


var data = {
    cates:category,
    status:false,
    title:"创建奖品",
    btnText:"保存",
    data:{
    }
};

window.onMessage('createPrize.status',function(prize){
    data.status = !status;
    if(prize){
        data.data = JSON.parse(JSON.stringify(prize.data));
        data.index = prize.index;
        data.btnText="确认修改";
    }else{
        data.data = {bizType:3};
    }
});

var CreateGame = {
    template: tpl,
    props:['prizes'],
    components:{
        scenes:scenes,
        uploadimg:uploadimg
    },
    data:function(){
        return data
    },
    methods:{
        submit:function(){
            var checkNull=false;
            var isEmpty=true;

            Object.keys(data.data).forEach(function(item){
                isEmpty=false;
                if(!data.data[item] && data.data[item]!==0){
                    checkNull=true;
                }
            });
            if(!isEmpty && !checkNull){
                if(data.btnText==='确认修改'){
                    window.sendMessage('createPrize.save',data.data)
                }else{
                    this.prizes.push(data.data);
                }
            }else{
                alert('请填写完整数据');
            }
        },
        listenmsgfromchild:function(src){
            data.data.iconUrl = src;
        }
    }
};

module.exports = CreateGame;